<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="部门经理" v-if="judgeShow('udf13')">
				<view v-for="(item, index) in udf13Name" :key="index" style="margin-left: 5px">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="采购人员" v-if="judgeShow('udf02')">
				<view v-for="(item, index) in udf01Name" :key="index" style="margin-left: 5px">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-divider color="#fa3534" type='warning'>请购单审批</u-divider>
			<u-form-item label="请购单别" v-if="judgeShow('ta001')">
				<u-input v-model="dataForm.ta001" placeholder="请购单别" :disabled="judgeWrite('ta001')"></u-input>
			</u-form-item>
			<u-form-item label="请购单号" v-if="judgeShow('ta002')">
				<u-input v-model="dataForm.ta002" placeholder="请购单号" :disabled="judgeWrite('ta002')"></u-input>
			</u-form-item>
			<u-form-item label="请购部门" v-if="judgeShow('ti006')">
				<u-tag :text="ti006Name" type="success" />
			</u-form-item>
			<u-form-item label="单据日期" v-if="judgeShow('ta013')">
				<u-input v-model="dataForm.ta013" placeholder="单据日期" :disabled="judgeWrite('ta013')"></u-input>
			</u-form-item>
			<u-form-item label="来源" v-if="judgeShow('ta009')">
				<view v-for="(item, index) in sourceList" :key="index" style="margin-left: 5px">
					<u-tag :text="item" />
				</view>
			</u-form-item>
			<u-form-item label="来源单号" v-if="judgeShow('ta005')">
				<u-input v-model="dataForm.ta005" placeholder="来源单号" :disabled="judgeWrite('ta005')"></u-input>
			</u-form-item>
			<u-form-item label="请购人员" v-if="judgeShow('ta012')">
				<u-tag :text="ta012Name" type="success" />
			</u-form-item>
			<u-form-item label="请购数量" v-if="judgeShow('ta011')">
				<u-input v-model="dataForm.ta011" placeholder="请购数量" :disabled="judgeWrite('ta011')"></u-input>
			</u-form-item>
			<u-divider color="#fa3534" type='warning' v-if="dataForm.purtbList!=0">详细信息</u-divider>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in dataForm.purtbList"
					:key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="品号" v-if="judgeShow('purtbList-tj004')">
						<u-input v-model="item.tb004" placeholder="品号"
							:disabled="judgeWrite('purtbList-tb004') "></u-input>
					</u-form-item>
					<u-form-item label="品名" v-if="judgeShow('purtbList-tb005')">
						<u-input v-model="item.tb005" placeholder="品名"
							:disabled="judgeWrite('purtbList-tb005') "></u-input>
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('purtbList-tb006')">
						<u-input v-model="item.tb006" placeholder="规格"
							:disabled="judgeWrite('purtbList-tb006') "></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('purtbList-tb007')">
						<u-input v-model="item.tb007" placeholder="单位"
							:disabled="judgeWrite('purtbList-tb007') "></u-input>
					</u-form-item>
					<u-form-item label="仓库" v-if="judgeShow('purtbList-tb008')">
						<u-input v-model="item.tb008" placeholder="仓库" disabled></u-input>
					</u-form-item>
					<!-- 				<u-form-item label="仓库名称" v-if="judgeShow('purtbList-tb008')">
						{{ warehouseNames[item.tb008] }}
					</u-form-item> -->
					<u-form-item label="请购数量" v-if="judgeShow('purtbList-tb009')">
						<u-input v-model="item.tb009" placeholder="请购数量"
							:disabled="judgeWrite('purtbList-tb009') "></u-input>
					</u-form-item>
					<u-form-item label="需求日期" v-if="judgeShow('purtbList-tb011')">
						<u-input v-model="item.tb011" placeholder="需求日期"
							:disabled="judgeWrite('purtbList-tb011') "></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('purtbList-tb012')">
						<u-input v-model="item.tb012" placeholder="备注"></u-input>
					</u-form-item>
				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	import {
		getPurta
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getDataInterfaceRes,
		getUserAll,
		Interface,
	} from '@/api/common'

	import comMixin from '../mixin'
	import {
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {
				dataForm: {},
				id: '',
				udf13Name: [],
				udf01Name: [],
				sourceList: [],
				ti006Name: '',
				ta012Name: '',
			}
		},

		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)
			},
			getInfo(data) {
				getPurta(data.id).then(res => {
					console.log('res', res);
					if (res.code == 200) {
						this.dataForm = res.data
						this.getUser()
						this.getDepartment(this.dataForm.ta004)
						this.getPersonnel(this.dataForm.ta012)
						this.getSource()
					}
				})
			},
			getUser() {
				getUserAll().then((res) => {
					this.udf13Name = res.data.filter((item) => this.dataForm.udf13.includes(item.id)).map((item) =>
						item.realName);
					this.udf01Name = res.data.filter((item) => this.dataForm.udf02.includes(item.account)).map((
							item) =>
						item.realName);
				});
			},
			// 获取部门
			getDepartment(id) {
				let interfaceId = '362111557984852549'
				let data = {
					id,
					interfaceId,
					propsValue: 'ME001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti006Name = res.data.JoinStr;
				})
			},
			// 获取人员
			getPersonnel(id) {
				let interfaceId = '438122284524265733'
				let data = {
					id,
					interfaceId,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ta012Name = res.data.JoinStr;
				})
			},
			// 获取仓库
			getWarehouse(item) {
				let interfaceId = '362114335423601221'
				let data = {
					id: item.tb008,
					interfaceId,
					propsValue: 'MC001',
					relationField: 'MC001',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.$set(item, 'tb008', MC002);
					return res.data.MC002
				})
			},
			getSource() {
				getDictionaryDataSelector("474002610777559109").then(res => {
					this.sourceList = res.data.list.filter((item) => this.dataForm.ta009.includes(item.enCode))
						.map((
								item) =>
							item.fullName);
				});
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},

		}
	}
</script>